/*
 * @Author: xiaobai123-4 1713951641@qq.com
 * @Date: 2025-03-26 09:46:43
 * @LastEditors: xiaobai123-4 1713951641@qq.com
 * @LastEditTime: 2025-03-26 09:51:58
 * @FilePath: \vite-grid-electron\main.cjs
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path')

function createWindow() {
  const mainWindow = new BrowserWindow({
    width: 1200,
    height: 800,
    webPreferences: {
      nodeIntegration: false,
      contextIsolation: true,
      devTools: true,
      preload: path.join(__dirname, 'preload.cjs')
    },
    // 是否显示边框
    frame: false,
    // 是否可调整大小
    resizable: true,
    // 是否可移动
    movable: true,
    useContentSize: false,
    // 是否可最小化
    minimizable: true,
    // 是否永远置顶
    alwaysOnTop: false,
    // 是否在任务栏显示
    skipTaskbar: false,
    fullscreen: false,
    // 显示
    // show: false,
  })

  mainWindow.loadFile(path.join(__dirname, 'dist', 'index.html'))

  ipcMain.on('minimize-window', () => {
    mainWindow.minimize();
  });

  ipcMain.on('maximize-window', () => {
    if (mainWindow.isMaximized()) {
      mainWindow.unmaximize();
    } else {
      mainWindow.maximize();
    }
  });

  ipcMain.on('close-window', () => {
    mainWindow.close();
  });

}

app.whenReady().then(() => {
  createWindow()

  app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) {
      createWindow()
    }
  })
})

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})